package com.probox.modules.controller.platfom;

import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.service.platfom.IPlatformGeneralsettingsService;
import com.probox.platform.api.domain.PlatformGeneralsettingsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 平台_店铺通用设置Controller
 *
 * @author usoft
 * @date 2021-07-08
 */
@RestController
@RequestMapping("/platform/generalsettings")
public class PlatformGeneralsettingsController extends BaseController {
    @Autowired
    private IPlatformGeneralsettingsService platformGeneralsettingsService;

    /**
     * 查询平台_店铺通用设置列表
     */
    @PreAuthorize(hasPermi = "platform:generalsettings:get")
    @GetMapping("/get")
    public AjaxResult list() {
        PlatformGeneralsettingsVo vo = platformGeneralsettingsService.get(SecurityUtils.getPlatformId());
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put("data",vo);
        ajaxResult.put("oldData",vo);
        return ajaxResult;
    }


    /**
     * 获取平台_店铺通用设置详细信息
     */
    @PreAuthorize(hasPermi = "platform:generalsettings:query")
    @GetMapping(value = "/{generalsettingsUid}")
    public AjaxResult getInfo(@PathVariable("generalsettingsUid") Long generalsettingsUid) {
        return AjaxResult.success(platformGeneralsettingsService.selectPlatformGeneralsettingsById(generalsettingsUid));
    }


    /**
     * 修改平台_店铺通用设置
     */
    @PreAuthorize(hasPermi = "platform:generalsettings:edit")
    @Log(title = "平台_店铺通用设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformGeneralsettingsVo vo) {
        return toAjax(platformGeneralsettingsService.updatePlatformGeneralsettings(vo));
    }

    @PostMapping
    public AjaxResult save(){
        return toAjax(platformGeneralsettingsService.insertPlatformGeneralsettings(SecurityUtils.getPlatformId()));
    }

    /**
     * 删除平台_店铺通用设置
     */
    @PreAuthorize(hasPermi = "platform:generalsettings:remove")
    @Log(title = "平台_店铺通用设置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{generalsettingsUids}")
    public AjaxResult remove(@PathVariable Long[] generalsettingsUids) {
        return toAjax(platformGeneralsettingsService.deletePlatformGeneralsettingsByIds(generalsettingsUids));
    }
}
